#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 19-5-23 下午6:30
# @Author  : Jason
# @Site    : 
# @File    : manage.py
# @Software: PyCharm

from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script import Manager
from info import db, creat_app,models
from info.models import User

# manage.py是程序的启动入口,只关心启动的相关参数以及内容,不关心具体该如何创建app或则相关业务逻辑
# from info.modules import passport



# 通过指定配置的名字创建对应的app
# create_app就类是于工厂方法
app=creat_app('development')
manager =Manager(app)
# python manager.py runserver
# 将app与db关联好
Migrate(app,db)
# 将迁移命令添加到manger
manager.add_command('db',MigrateCommand)

@manager.option('-n','-name',dest='name')
@manager.option('-p','-password',dest='password')
def createsuperuser(name,password):
   if not all([name,password]):
      print('参数不足')
   user =User()
   user.nick_name =name
   user.mobile = name
   user.password =password
   user.is_admin=True
   try:
         db.session.add(user)
         db.session.commit()
   except Exception as e:
         db.session.rollback()
         print(e)
   print('添加成功')


if __name__ == '__main__':
   manager.run()